package com.yaodian100.ec.product.service;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.ec.product.entity.AddOnProduct;
import com.yaodian100.ec.product.entity.Brand;
import com.yaodian100.ec.product.entity.Product;
import com.yaodian100.ec.product.entity.ProductCategory;
import com.yaodian100.ec.product.entity.ProductPromotionFlag;
import com.yaodian100.ec.product.entity.Specification;
import com.yaodian100.ec.product.entity.SpecificationInventory;
import com.yaodian100.ec.product.entity.SpecificationMajor;
import com.yaodian100.ec.product.entity.ViewPickProduct;
import com.yaodian100.ec.product.entity.VirtualProduct;
import com.yaodian100.ec.shelf.entity.Shelf;
import com.yaodian100.ec.shelf.entity.ViewShelf;
import com.yaodian100.ec.supplierapply.entity.SupplierApply;

/**
 * 20110325 雙屬性專案暫停開發
 * 
 * @author feeling.wang
 * 
 */
public interface Product2Service extends DomainService<Product> {

	/* ========================== Product ========================= */
	/**
	 * 复制商品
	 * 
	 * @param product
	 * @param productPromotionFlag
	 * @return
	 * @throws CoreException
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	public Product copyProduct(String copyProductId) throws CoreException, IllegalAccessException,
			InvocationTargetException;

	/**
	 * 查询ｎ选ｍ商品
	 * 
	 * @param firstResult
	 * @param maxResults
	 * @param criteria
	 * @param sortOrder
	 * @return
	 * @throws CoreException
	 */
	public List<ViewPickProduct> getViewPickProductList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	/**
	 * 取得n选m商品笔数
	 * 
	 * @param criteria
	 * @return
	 * @throws CoreException
	 */
	public Number getViewPickProductListSize(CommonCriteria criteria) throws CoreException;

	/**
	 * 商品異動(雙屬性),要sync 1.update Product 2.update ProductCategory 3.update PromotionFlag
	 * 
	 * @param entity
	 * @return
	 * @throws CoreException
	 */
	public Product saveProductPage(Product product) throws CoreException;

	/**
	 * 商品主檔異動(雙屬性) 1.update Specification 2.update SpecificationMajor 3.update Product
	 * 
	 * @param entity 商品主檔
	 * @param isSync 是否要同步
	 * @return
	 */
	public Product saveOrUpdateProduct(Product entity, boolean isSync);

	/**
	 * 批次修改商品採購模式為BO
	 * 
	 * @param supplierId
	 * @return
	 * @throws CoreException
	 */
	public boolean updateIsScmToBOBatch(String supplierId) throws CoreException;

	/**
	 * 批次商品成本異動
	 * 
	 * @param productId[],cost[]
	 * @return
	 */
	public String updateProductCostArray(String[] productId, BigDecimal[] cost) throws CoreException;

	public List getProductIds(int firstResult, int maxResults, CommonCriteria criteria, String[] sortOrder)
			throws CoreException;

	public List<Product> getProductOnShelfPageableList(String prodId, String prodName, String prodType, String prodAttr,
			String supplierId, String categoryPath, String productBrand, int firstResult, int maxResults)
			throws CoreException;

	public Number getProductOnShelfPageableListSize(String prodId, String prodName, String prodType, String prodAttr,
			String supplierId, String categoryPath, String productBrand);

	/** 將brief,description,details 檔案讀出 */
	public String readFromFile(String productId, String contextType) throws CoreException;

	/**
	 * 读取default馆别的购物须知檔
	 * 
	 * @param categoryId
	 * @return
	 * @throws CoreException
	 * @Deprecated
	 */

	public String readOrderNotice(String categoryId) throws CoreException;

	/**
	 * 商品頁搜尋條件
	 * 
	 * @param searchMap
	 * @param firstResult
	 * @param maxResults
	 * @return
	 * @throws CoreException
	 */
	public List<Product> getProductPageableList(Map<String, String> searchMap, int firstResult, int maxResults)
			throws CoreException;

	/**
	 * 商品頁搜尋條件筆數
	 * 
	 * @param searchMap
	 * @return
	 * @throws CoreException
	 */
	public Number getProductPageableListSize(Map<String, String> searchMap) throws CoreException;

	/* ========================== Brand ========================== */
	public void delBrand(Brand brand) throws CoreException;

	public Brand getBrandByBrandId(String brandId) throws CoreException;

	public List<Brand> getBrandList(int firstResult, int maxResults, CommonCriteria criteria, String[] sortOrder)
			throws CoreException;

	public String readBrandFromFile(String brandId) throws CoreException;

	/* ========================== ProductCategory ========================== */
	/**
	 * 依館id查詢在該館的所有商品
	 * 
	 * @param categoryId
	 * @return
	 * @throws CoreException
	 */
	public List<Object> getProductCategoryByCategoryId(Long categoryId, String isDelete) throws CoreException;

	public List<Object> getProductCategoryByCategoryId(Long categoryId, List<String> isDelete) throws CoreException;

	public ProductCategory getProductCategory(Long id) throws CoreException;

	/**
	 * 取得商品上架目錄清單
	 * 
	 * @param productId
	 * @return mapEntity.key 為 categoryId
	 * @throws CoreException
	 */
	public Map<String, ProductCategory> getProductCategoryByProduct(String productId) throws CoreException;

	public List<ProductCategory> getProductCategoryList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	public boolean deleteProductCategory(String[] id) throws CoreException;

	public void delProductCategory(ProductCategory productCategory) throws CoreException;

	/* ========================== ProductPromotionFlag ========================== */
	public void delProductPromotionFlag(ProductPromotionFlag productPromotionFlag) throws CoreException;

	/* ========================== VirtualProduct ========================== */
	public void delVirtualProduct(VirtualProduct virtualProduct) throws CoreException;

	/* ========================== AddOnProduct ========================== */

	public AddOnProduct getAddOnProduct(String mainProductId, String addOnProductId) throws CoreException;

	public AddOnProduct getAddOnProductById(Long addOnId) throws CoreException;

	public List<AddOnProduct> getAddOnProductList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	public List<String> getAddOnProductList(String mainProductId, String addOnProductId, String status, int firstResult,
			int maxResults) throws CoreException;

	/**
	 * 回传有效的 addOnProduct. mainProductId=${mainProductId} and isEnable="Y" and isDelete="N" and startDate<=now and
	 * endDate>=now
	 * 
	 * @param mainProductId
	 * @return Map<AddOnProduct.addOnProductId, AddOnProduct>
	 * @throws CoreException
	 */
	public Map<String, AddOnProduct> getAddOnProducts(String mainProductId, boolean nmProduct) throws CoreException;

	public ProductPromotionFlag getProductPromotionFlag(String productId) throws CoreException;

	public List<ProductPromotionFlag> getProductPromotionFlagList(int firstResult, int maxResults,
			CommonCriteria criteria, String[] sortOrder) throws CoreException;

	public String getProposeProductIdNo() throws CoreException;

	/* ========================== Specification ========================== */

	/**
	 * @param specId
	 * @return
	 * @throws CoreException
	 */
	public Specification getSpecification(Long specId) throws CoreException;

	public List<Specification> getSpecificationList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	/**
	 * @param productId
	 * @return
	 * @throws CoreException
	 */
	public Map<String, Specification> getSpecifications(String productId) throws CoreException;

	/* ========================== SpecificationInventory ========================== */

	public List<SpecificationInventory> getSpecificationInventory(CommonCriteria criteria) throws CoreException;

	public SpecificationInventory getSpecificationInventory(String productId, Long specId) throws CoreException;

	public Map<String, String> getSpecificationinventoryDaoSum(List products) throws CoreException;

	public Map<String, SpecificationInventory> getSpecificationInventoryMap(String productId) throws CoreException;

	/* ========================== 缺貨報表 ========================== */
	public List<Object> getStockOutReport(Long categoryId, String isDelete, String pmId, String productId,
			String productName, String supplier, boolean stockNotify, int startStockQty, int endStockQty,
			String categoryLevel1Param) throws CoreException;

	public int getStockOutByProductId(String productId);

	/* ========================== SupplierApply ========================== */
	public List<SupplierApply> getSupplierApplyList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	public List<VirtualProduct> getVirtualProductList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	/* 立即購買 */
	public ArrayList<String> orderBuyNowInfo(String[] itemNo, String[] specNo, String[] qty, String[] categoryPath,
			String[] type, String presents, String addOns) throws CoreException;

	/* 搭售 / 加價購 / 贈品 / 加一元多一件 */
	public void saveAddOnProduct(AddOnProduct addOnProduct) throws CoreException;

	/* 品牌資料 */
	public Brand saveBrand(Brand brand) throws CoreException;

	public void saveBrandToFile(String brandId, String context) throws CoreException;

	/**
	 * 搭售 / 加價購 / 贈品 / 加一元多一件批次更新
	 * 
	 * @param addOnProducts
	 * @throws CoreException
	 */
	public boolean saveOrUpdateAddOnProductBatch(List<AddOnProduct> addOnProducts, List<AddOnProduct> removeProducts)
			throws CoreException;

	public Product saveOrUpdateProductByPickProduct(Product product, ProductPromotionFlag productPromotionFlag)
			throws CoreException, IllegalAccessException, InvocationTargetException;

	/**
	 * 新增/修改 n选m上架檔资料
	 * 
	 * @param shelf
	 * @param product
	 * @return
	 * @throws CoreException
	 */
	public Shelf saveOrUpdateShelfByPickProduct(Shelf shelf, Product product) throws CoreException;

	public void saveProductCategory(ProductCategory productCategory) throws CoreException;

	/* 商品前台促銷設定檔 */
	public void saveProductPromotionFlag(ProductPromotionFlag productPromotionFlag) throws CoreException;

	public void saveSpecification(Specification specification) throws CoreException;

	public void saveSpecificationInventory(SpecificationInventory specificationInventory) throws CoreException;

	public void saveSpecificationInventoryAndInvalid(SpecificationInventory specificationInventory, String invHistoryId)
			throws CoreException;

	public void saveVirtualProduct(VirtualProduct virtualProduct) throws CoreException;

	public Product updateNoSync(Product entity) throws CoreException;

	public void saveBatchSpecification(List<Specification> specList) throws CoreException;

	/**
	 * 修改n选m商品
	 * 
	 * @param entity
	 * @return
	 * @throws CoreException
	 */
	public Product updatePickProduct(Product entity) throws CoreException;

	public boolean updateProductCategory(String[] id, String showSeq[]) throws CoreException;

	public boolean updateProductCategory(String[] id, String categoryId, String func) throws CoreException;

	/**
	 * 商品是否有庫存
	 * 
	 * @param mainProduct
	 * @return
	 */
	public boolean chkProductHasInventory(Product mainProduct);

	/**
	 * 商品主目錄搬家
	 * 
	 * @param products
	 * @param oldCateId
	 * @param newCateId
	 * @param delOldCateId
	 * @return
	 * @throws CoreException
	 */
	public boolean saveOrUpdateMainProductCategoryBatch(List<Product> products, String oldCateId, String newCateId,
			boolean delOldCateId) throws CoreException;

	/**
	 * 依主商品查詢搭售商品的庫存數
	 * 
	 * @param productId
	 * @return
	 */
	public List<Object> getAddonProductInvByMainProduct(String productId);

	// 已销售未出货的库存查询
	public List<Object> orderNotShipping(String productId, String specId) throws Exception;

	/**
	 * 查詢主規格表
	 * 
	 * @param criteria
	 * @param sortOrder
	 * @return
	 * @throws CoreException
	 */
	public List<SpecificationMajor> getSpecificationMajorList(CommonCriteria criteria, String[] sortOrder)
			throws CoreException;

	/**
	 * 查询主规格表
	 * 
	 * @param oid
	 * @return
	 * @throws CoreException
	 */
	public SpecificationMajor getSpecificationMajor(Long oid) throws CoreException;

	/**
	 * 查询ｎ选ｍ商品
	 * 
	 * @param queryParam
	 * @return
	 * @throws CoreException
	 */
	public List<Map<String, Object>> getPickProductList(Map<String, String> queryParam) throws CoreException;

	/**
	 * 查询ｎ选ｍ商品數量
	 * 
	 * @param queryParam
	 * @return
	 * @throws CoreException
	 */
	public Number getPickProductListSize(Map<String, String> queryParam) throws CoreException;

	/**
	 * 搬移商品主目录(批次用)
	 * 
	 * @param pc
	 * @return
	 */
	public ProductCategory moveMainCategoryOfProduct(ProductCategory pc);

	/**
	 * 限制COD商品检核报表
	 * 
	 * @param canUseCod
	 * @param saleStatus
	 * @param shelfPrice
	 * @return
	 */
	public List<ViewShelf> getCODLimitProduct(String canUseCod, String saleStatus, String shelfPrice);

	/**
	 * @param productIds
	 * @param productName
	 * @param categoryPath
	 * @param eqData
	 * @param neData
	 * @param inData
	 * @param hasShelf
	 * @param firstResult
	 * @param maxResults
	 * @param sortBy
	 * @return
	 * @throws CoreException
	 */
	public List<Product> getProductAttrListForAddonProductAdd(List productIds, String productName, String categoryPath,
			Map eqData, Map neData, Map inData, Boolean hasShelf, int firstResult, int maxResults, String[] sortBy)
			throws CoreException;

	public Number getProductAttrListForAddonProductAddSize(List productIds, String productName, String categoryPath,
			Map eqData, Map neData, Map inData, Boolean hasShelf) throws CoreException;

	public List<Object[]> getProductAttrListForAddonProductUpdate(List productIds, String productName,
			String paramAddOnProductId, String categoryPath, String searchStartDate, String searchEndDate, Map eqData,
			Map neData, Map inData, Boolean hasShelf, int firstResult, int maxResults, String[] sortBy) throws CoreException;

	public Number getProductAttrListForAddonProductUpdateSize(List productIds, String productName,
			String paramAddOnProductId, String categoryPath, String searchStartDate, String searchEndDate, Map eqData,
			Map neData, Map inData, Boolean hasShelf) throws CoreException;

	public AddOnProduct getAddOn(String id) throws CoreException;

	/**
	 * 检查是否有大材积商品
	 * 
	 * @param productId
	 * @return
	 * @throws CoreException
	 */
	public boolean chkVolumeOfProduct(String productId) throws CoreException;

	/**
	 * 取得nm商品中，精品的數量
	 * 
	 * @param mainProductId
	 * @return
	 * @throws CoreException
	 */
	public Long getLuxAddOnCount(String mainProductId) throws CoreException;

	/**
	 * 取得nm商品中，非精品的數量
	 * 
	 * @param mainProductId
	 * @return
	 * @throws CoreException
	 */
	public Long getNmlAddOnCount(String mainProductId) throws CoreException;

	/**
	 * 依商品編號查詢可銷售的spec可售數加總
	 * 
	 * @param productId
	 * @return
	 * @throws CoreException
	 */
	public int getSpecificationInventorySum(String productId) throws CoreException;

	/**
	 * 依商品編號查詢可銷售的spec可售數加總
	 * 
	 * @param productId
	 * @return
	 * @throws CoreException
	 */
	public Map<String, Integer> getSpecInventorySum(Map<String, Product> prdMap) throws CoreException;

}
